package com.sskj.jingbi.http;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.App;
import com.sskj.common.base.HttpData;
import com.sskj.common.http.WebSocketObserver;
import com.sskj.lib.bean.AppVersionBean;
import com.sskj.lib.bean.GonggaoBean;
import com.sskj.lib.bean.SocketSendBean;
import com.sskj.lib.bean.WSFiveBean;
import com.sskj.lib.util.APKVersionCodeUtils;

import java.util.List;

import okhttp3.WebSocket;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {





    public WebSocketObserver pushCoinType() {
        return new WebSocketObserver(HttpConfig.WS_BASE_URL) {
            @Override
            public void onOpen(WebSocket webSocket, okhttp3.Response response, String msg) {
                webSocket.send("{\"sub\":\"ticker.all\"}");
            }
        };
    }

    public WebSocketObserver pushCoinTrade(String code) {
        return new WebSocketObserver(HttpConfig.WS_FIVE_TRADE_BASE_URL) {
            @Override
            public void onOpen(WebSocket webSocket, okhttp3.Response response, String msg) {

                webSocket.send(new Gson().toJson(new SocketSendBean(code)));
            }
        };
    }


    public GetRequest<HttpData<List<WSFiveBean>>> getDeepData(String code) {
        return OkGo.<HttpData<List<WSFiveBean>>>get(HttpConfig.BASE_URL + HttpConfig.GET_DEEP)
                .params("code", code)
                ;
    }



    public WebSocketObserver pushCoinFiveDeep(String type) {
        return new WebSocketObserver(HttpConfig.WS_FIVE_DEEP_BASE_URL) {
            @Override
            public void onOpen(WebSocket webSocket, okhttp3.Response response, String msg) {

                webSocket.send(new Gson().toJson(new SocketSendBean(type)));
            }
        };
    }

    public GetRequest<HttpData<GonggaoBean>> getGonggao() {
        return OkGo.<HttpData<GonggaoBean>>get(HttpConfig.BASE_URL + HttpConfig.GET_GONGGAO)
                ;
    }

    public PostRequest<HttpData<AppVersionBean>> getVersion() {
        return OkGo.<HttpData<AppVersionBean>>post(HttpConfig.BASE_URL + HttpConfig.VERSION)
                .params("version", APKVersionCodeUtils.getVerName(App.INSTANCE))
                .params("type", "1");


    }

    public PostRequest<HttpData> checkCode(String account, String code) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.CHECK_CODE)
                .params("mobile", account)
                .params("code", code);

    }



}